﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using DataAccess;

namespace UI
{
    public partial class Administration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //RoomsGridView.Visible = false;
            //DisplayRoomsInformation();

            //Table tbl = new Table();
            //DropDownList ddList = new DropDownList();
            //ddList.Width = 160;
            //ddList.Items.Add("Select");
            //ddList.Items.Add("Campuses");
            //ddList.Items.Add("Buildings");
            //ddList.Items.Add("Rooms");
            //TableHolder.Controls.Add(tbl);


            //tbl.Controls.Add(TableCreator.CreateRowWithDDList(ddList, "ddList"));
            //tbl.Controls.Add(TableCreator.CreateRowWithButtons("Edit", "Add", "buttonCell"));

            
            Table tbl = new Table();
            TableHolder.Controls.Add(tbl);
            //div2.Controls.Add(tbl);

            TableHeaderRow header = new TableHeaderRow();
            TableCell cell = new TableCell();
            header.CssClass = "loginTable";
            DropDownList ddlist = new DropDownList();
            ddlist.Items.Add("Select");
            ddlist.Items.Add("Campuses");
            ddlist.Items.Add("Buildings");
            ddlist.Items.Add("Rooms");
            cell.Controls.Add(ddlist);
            header.Controls.Add(cell);
            tbl.Controls.Add(header);

            //2nd row
            TableRow row = new TableRow();
            TableCell edit_cell = new TableCell();
            edit_cell.Controls.Add(edit_btn);
            row.Controls.Add(edit_cell);

            TableCell add_cell = new TableCell();
            add_cell.Controls.Add(add_btn);            
            row.Controls.Add(add_cell);
            tbl.Controls.Add(row);
        }


        public void Edit_Command(object sender, EventArgs e)
        {
            RoomsGridView.Visible = true;
            DisplayRoomsInformation();
        }


        public void Add_Command(object sender, EventArgs e)
        {
            RoomsGridView.Visible = false;
           
        }


        private void DisplayRoomsInformation()
        {
            try
            {
                using (SqlDataReader reader = RoomDAC.GetRoomInformation())
                {
                    RoomsGridView.DataSource = reader;
                    RoomsGridView.DataBind();
                }
            }
            catch (SqlException ex)
            {
                StatusLabel.Text = ex.Message;
            }
        }
    }
}